/*package com.znf4.controller.sett;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.bigpay.account.entity.RpRemitApplication;
import com.bigpay.account.enums.SettRecordStatusEnum;
import com.bigpay.account.service.RpAccountService;
import com.bigpay.account.service.RpRemitApplicationService;
import com.bigpay.account.service.RpSettHandleService;
import com.bigpay.account.service.RpSettQueryService;
import com.bigpay.common.core.entity.ApiCommonResultVo;
import com.bigpay.common.core.exception.BizException;
import com.bigpay.common.core.page.PageBean;
import com.bigpay.common.core.page.PageParam;
import com.bigpay.common.core.utils.EncryptUtil;
import com.bigpay.common.core.utils.ProxyPayXlsUtils;
import com.bigpay.common.core.utils.StringUtil;
import com.bigpay.trade.service.RpTradePaymentManagerService;
import com.bigpay.user.entity.RpUserInfo;
import com.bigpay.user.entity.RpUserPayConfig;
import com.bigpay.user.enums.BankAccountTypeEnum;
import com.bigpay.user.enums.BankCodeEnum;
import com.bigpay.user.enums.CardTypeEnum;
import com.bigpay.user.service.RpUserPayConfigService;
import com.znf4.controller.common.BaseController;
import com.znf4.controller.common.ConstantClass;
import com.znf4.controller.common.JSONParam;

*//**
 * 结算信息
 *//*
@Controller
@RequestMapping("/merchant/remitApply")
public class RemitApplyController extends BaseController {
	private static final Log LOG = LogFactory.getLog(RemitApplyController.class);
	@Autowired
	private RpSettHandleService rpSettHandleService;
	@Autowired
	private RpSettQueryService rpSettQueryService;
	@Autowired
	private RpAccountService rpAccountService;
	@Autowired
	private RpRemitApplicationService rpRemitApplicationService;
	@Autowired
	private RpTradePaymentManagerService rpTradePaymentManagerService;
	@Autowired
	private RpUserPayConfigService rpUserPayConfigService;

	*//**
	 * 函数功能说明 ： 查询结算记录
	 * 
	 * @参数： @return @return String @throws
	 *//*
	@RequestMapping(value = "/getRemitApplyList", method = { RequestMethod.POST, RequestMethod.GET })
	public String getAccountInfo(HttpServletRequest request) {

		return "sett/remitApply";
	}

	@RequestMapping(value = "/ajaxRemitApplyList", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String ajaxPaymentList(HttpServletRequest request, @RequestBody JSONParam[] params) throws IllegalAccessException, InvocationTargetException {
		// convertToMap定义于父类，将参数数组中的所有元素加入一个HashMap
		HashMap<String, String> paramMap = convertToMap(params);
		String sEcho = paramMap.get("sEcho");
		int start = Integer.parseInt(paramMap.get("iDisplayStart"));
		int length = Integer.parseInt(paramMap.get("iDisplayLength"));
		String beginDate = paramMap.get("beginDate");
		String endDate = paramMap.get("endDate");
		if (StringUtil.isEmpty(beginDate) && !StringUtil.isEmpty(endDate)) {
			beginDate = endDate;
		}
		if (StringUtil.isEmpty(endDate) && !StringUtil.isEmpty(beginDate)) {
			endDate = beginDate;
		}
		String outTradeNo = paramMap.get("outTradeNo");
		String status = paramMap.get("status");
		RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		RpUserPayConfig rpUserPayConfig = rpUserPayConfigService.getByUserNo(userInfo.getUserNo());
		// 页面当前页需要显示的记录数据
		PageParam pageParam = new PageParam(start / length + 1, length);
		Map<String, Object> settMap = new HashMap<String, Object>();
		settMap.put("payKey", rpUserPayConfig.getPayKey());
		settMap.put("status", status);
		settMap.put("outTradeNo", outTradeNo);
		settMap.put("beginDate", beginDate);
		settMap.put("endDate", endDate);
		PageBean pageBean = rpRemitApplicationService.queryRemitApplicationListPage(pageParam, settMap);
		Long count = Long.valueOf(pageBean.getTotalCount() + "");

		String jsonString = JSON.toJSONString(pageBean.getRecordList());
		String json = "{\"sEcho\":" + sEcho + ",\"iTotalRecords\":" + count.longValue() + ",\"iTotalDisplayRecords\":" + count.longValue() + ",\"aaData\":" + jsonString + "}";
		return json;
	}

	@RequestMapping(value = "/launchSett", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ApiCommonResultVo launchSett(HttpServletRequest request) throws IllegalAccessException, InvocationTargetException {
		RpUserInfo rpUserInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		String settAmount = request.getParameter("settAmount");
		try {
			rpSettHandleService.launchSett(rpUserInfo.getUserNo(), new BigDecimal(settAmount));
		} catch (BizException e) {
			return new ApiCommonResultVo(-1, e.getMsg(), "");
		}
		return new ApiCommonResultVo(0, "操作成功", "");
	}

	*//**
	 * 申请打款
	 * 
	 * @param id
	 * @param dId
	 * @param fieldCode
	 * @return
	 *//*
	@RequestMapping(value = "/apply", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ApiCommonResultVo apply(@RequestParam(value = "payPass") String payPass, @RequestParam(value = "id") String id, HttpSession session) {
		RpUserInfo rpUserInfo = (RpUserInfo) session.getAttribute(ConstantClass.USER);
		if(!rpUserInfo.getPayPwd().equals(EncryptUtil.encodeMD5String(payPass, rpUserInfo.getUserNo()))){
			return new ApiCommonResultVo(-1, "支付密码不正确", "");
		}
		RpRemitApplication rpRemitApplication = rpRemitApplicationService.getDataById(id);//通过id获取记录
		if (rpRemitApplication.getStatus().equals(SettRecordStatusEnum.WAIT_CONFIRM.name())) {//等待审核状态
			try {
				String remitRequestNo = rpAccountService.buildRemitRequestNo();
				rpRemitApplicationService.remitApply(rpRemitApplication, remitRequestNo);//申请打款
			} catch (BizException e) {
				return new ApiCommonResultVo(-1, e.getMsg(), "");
			}
		} else {
			return new ApiCommonResultVo(-1, "不能重复申请打款", "");
		}
		return new ApiCommonResultVo(0, "操作成功", "");
	}

	*//**
	 * 函数功能说明：excel上传.
	 * 
	 * @return void @throws
	 *//*
	@RequestMapping(value = "/importExcel", method = { RequestMethod.POST, RequestMethod.GET, RequestMethod.HEAD })
	@ResponseBody
	public ApiCommonResultVo importExcel(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException {
		RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		RpUserPayConfig rpUserPayConfig = rpUserPayConfigService.getByUserNo(userInfo.getUserNo());
		StringBuffer buffer = new StringBuffer("");
		if (!file.isEmpty()) {
			String name = file.getOriginalFilename();
			String str = name.split("\\.")[1];
			if ("xls".equals(str) || "xlsx".equals(str)) {
				List<RpRemitApplication> list = new ArrayList<RpRemitApplication>();

				for (String[] strArray : ProxyPayXlsUtils.rosolveFile(file.getInputStream(), str, 2)) {
					RpRemitApplication remit = new RpRemitApplication();
					remit.setId(StringUtil.get32UUID());
					remit.setPayKey(rpUserPayConfig.getPayKey());
					if (StringUtil.isEmpty(strArray[1])) {
						String remitRequestNo = rpAccountService.buildRemitRequestNo();
						remit.setOutTradeNo(remitRequestNo);
					} else {
						remit.setOutTradeNo(strArray[1].replaceAll(",", ""));
					}
					// 银行卡号
					if (StringUtil.isEmpty(strArray[2])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setBankAccountNo(strArray[2]);
					}
					// 银行账户名
					if (StringUtil.isEmpty(strArray[3])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setBankAccountName(strArray[3]);
					}
					// 银行卡类型
					if (StringUtil.isEmpty(strArray[4])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						String bankAccountType = BankAccountTypeEnum.PRIVATE_DEBIT_ACCOUNT.name();
						if ("2".equals(strArray[4])) {
							bankAccountType = BankAccountTypeEnum.PUBLIC_ACCOUNT.name();
						}
						remit.setBankAccountType(bankAccountType);
					}
					// 代付金额
					if (StringUtil.isEmpty(strArray[5])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setSettAmount(new BigDecimal(strArray[5].replaceAll(",", "")));
					}
					// 手机号
					if (StringUtil.isEmpty(strArray[6])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setPhoneNo(strArray[6].replaceAll(",", ""));
					}
					// 银行名
					if (StringUtil.isEmpty(strArray[7])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setBankCode(strArray[7]);
						BankCodeEnum codeEnum = BankCodeEnum.getEnum(strArray[7]);
						if (codeEnum != null) {
							remit.setBankName(codeEnum.name());
						} else {
							remit.setBankName(strArray[7]);
						}
					}
					// 联行号
					if (StringUtil.isEmpty(strArray[8])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setBankBranchNo(strArray[8]);
						remit.setBankClearNo(strArray[8]);
					}
					// 支行名称
					if (StringUtil.isEmpty(strArray[9])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setBankBranchName(strArray[9]);
					}
					// 交易类型
					if (StringUtil.isEmpty(strArray[10])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setProxyType(strArray[10]);
					}
					// 产品类型
					if (StringUtil.isEmpty(strArray[11])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setProductType(strArray[11]);
					}
					// 开户行所在省
					if (StringUtil.isEmpty(strArray[12])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setProvince(strArray[12]);
					}
					// 开户行所在市
					if (StringUtil.isEmpty(strArray[13])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setCity(strArray[13]);
					}
					// 开户人身份证
					if (StringUtil.isEmpty(strArray[14])) {
						// 为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					} else {
						remit.setCardType(CardTypeEnum.IDENTITY.name());
						remit.setCardNo(strArray[14].replaceAll(",", ""));
					}
					// 状态
					remit.setStatus(SettRecordStatusEnum.WAIT_CONFIRM.name());
					remit.setEditTime(new Date());
					remit.setCreateTime(new Date());
					list.add(remit);
				}
				rpRemitApplicationService.saveRemitApplicationList(list);
			}else{
				throw new BizException("上传文件类型不正确");
			}

		}else{
			throw new BizException("上传文件为空");
		}
		return new ApiCommonResultVo(0, "操作成功", "");
	}
	
	
	
	*//**
	 * 添加结算申请
	 * @param response
	 * @param request
	 * @return
	 * @throws IOException
	 *//*
	@RequestMapping(value = "/addRemitApply", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ApiCommonResultVo addRemitApply(HttpServletResponse response, HttpServletRequest request) throws IOException {
		//获取前台参数
		String bankAccountNo = request.getParameter("bankAccountNo");
		String bankAccountName = request.getParameter("bankAccountName");
		String bankAccountType = request.getParameter("bankAccountType");
		String settAmount = request.getParameter("settAmount");
		String phoneNo = request.getParameter("phoneNo");
		String bankCode = request.getParameter("bankCode");
		String cardNo = request.getParameter("cardNo");
		String proxyType = request.getParameter("proxyType");
		String productType = request.getParameter("productType");
		
		
		if(StringUtil.isEmpty(bankAccountNo)) {
			return new ApiCommonResultVo(-1,"操作失败,结算账号为空","");
		}
		if(StringUtil.isEmpty(bankAccountName)) {
			return new ApiCommonResultVo(-1,"操作失败,结算户名为空","");
		}
		if(StringUtil.isEmpty(bankAccountType)) {
			return new ApiCommonResultVo(-1,"操作失败,账户类型为空","");
		}
		if(StringUtil.isEmpty(settAmount)) {
			return new ApiCommonResultVo(-1,"操作失败,结算金额为空","");
		}
		if(StringUtil.isEmpty(phoneNo)) {
			return new ApiCommonResultVo(-1,"操作失败,收款人手机号为空","");
		}
		if(StringUtil.isEmpty(cardNo)) {
			return new ApiCommonResultVo(-1,"操作失败,银行类别为空","");
		}
		if(StringUtil.isEmpty(bankCode)) {
			return new ApiCommonResultVo(-1,"操作失败,银行类别为空","");
		}
		if(StringUtil.isEmpty(proxyType)) {
			return new ApiCommonResultVo(-1,"操作失败,交易类型为空","");
		}
		if(StringUtil.isEmpty(productType)) {
			return new ApiCommonResultVo(-1,"操作失败,产品类型为空","");
		}
		RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		RpRemitApplication remit = new RpRemitApplication();
		remit.setId(StringUtil.get32UUID());
		RpUserPayConfig rpUserPayConfig = rpUserPayConfigService.getByUserNo(userInfo.getUserNo());
		remit.setPayKey(rpUserPayConfig.getPayKey());//获取支付key
		String remitRequestNo = rpAccountService.buildRemitRequestNo();//获取请求号
		remit.setOutTradeNo(remitRequestNo);
		remit.setBankAccountNo(bankAccountNo);//银行卡号
		remit.setBankAccountName(bankAccountName);//银行账户名
		remit.setBankAccountType(bankAccountType);//银行卡类型
		remit.setSettAmount(new BigDecimal(settAmount));//代付金额
		remit.setPhoneNo(phoneNo);//手机号
		remit.setBankCode(bankCode);
		BankCodeEnum codeEnum = BankCodeEnum.getEnum(bankCode);
		remit.setBankName(codeEnum.name());//银行名
		remit.setBankBranchNo("123456789");//联行号
		remit.setBankClearNo("123456789");
		remit.setBankBranchName("zhmc");//支行名称		
		remit.setProxyType(proxyType);//交易类型
		remit.setProductType(productType);//产品类型
		remit.setProvince("xxx省");//开户行所在省
		remit.setCity("xxx市");//开户行所在市
		remit.setCardType(CardTypeEnum.IDENTITY.name());//开户人证件
		remit.setCardNo(cardNo);//收款人手机号
		remit.setStatus(SettRecordStatusEnum.WAIT_CONFIRM.name());//状态
		remit.setEditTime(new Date());
		remit.setCreateTime(new Date());
		try {
			rpRemitApplicationService.saveRemitApplication(remit);	
		}catch (Exception e) {
			return new ApiCommonResultVo(-1, "操作失败", "");
		}
		return new ApiCommonResultVo(0, "操作成功", "");
	}
	
	
	
	
	
	
	
	
	
}
*/